package com.mate.cloud.uid;


import com.mate.cloud.uid.impl.CachedUidGenerator;
import org.jasypt.encryption.StringEncryptor;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

@SpringBootTest
public class UidApplicationTests {

    @Resource
    private StringEncryptor stringEncryptor;

    @Resource
    private CachedUidGenerator uidGenerator;

    @Test
    public void encrypt() {
        String encrypt = stringEncryptor.encrypt("im01");
        String encryptPwd = stringEncryptor.encrypt("cadt@123!");

        //UUID  加密后的内容：AkZs6tdmJojZe74vfIi5BRXbUvqkBiNQrn3RO22GeqW9sBjbNuIcNz+GdqkqJ8DQ
        System.out.println("im01：" + encrypt);
        System.out.println("cadt@123!：" + encryptPwd);
        // 解密
        String decrypt = stringEncryptor.decrypt(encrypt);
        String decryptPwd = stringEncryptor.decrypt(encryptPwd);
        System.out.println("解密后的内容：" + decrypt);
        System.out.println("解密后的内容：" + decryptPwd);
    }

    @Test
    public void genUidTest() throws Exception {
        // Generate UID
        long uid = uidGenerator.getUID();

        System.out.println("UID:" + uidGenerator.parseUID(uid));

        for (int i = 0; i < 10; i++) {
            System.out.println("uid:" + uidGenerator.getUID());
        }

    }
}
